"""
来源管理模型
"""
from enum import Enum
from typing import Optional
from datetime import datetime
from pydantic import BaseModel, Field

class ModuleType(str, Enum):
    """模块类型"""
    PROJECT = "project"
    REQUIREMENT = "requirement"
    TASK = "task"
    DEFECT = "defect"
    TEST_CASE = "test_case"

class SourceBase(BaseModel):
    """来源基础模型"""
    name: str = Field(..., description="来源名称")
    code: str = Field(..., description="来源代码")
    module_type: str = Field(..., description="模块类型")
    description: Optional[str] = Field(None, description="来源描述")
    color: Optional[str] = Field("#1890ff", description="来源颜色")
    sort_order: Optional[int] = Field(0, description="排序顺序")
    is_enabled: Optional[bool] = Field(True, description="是否启用")

class SourceCreate(SourceBase):
    """创建来源模型"""
    pass

class SourceUpdate(BaseModel):
    """更新来源模型"""
    name: Optional[str] = Field(None, description="来源名称")
    code: Optional[str] = Field(None, description="来源代码")
    description: Optional[str] = Field(None, description="来源描述")
    color: Optional[str] = Field(None, description="来源颜色")
    sort_order: Optional[int] = Field(None, description="排序顺序")
    is_enabled: Optional[bool] = Field(None, description="是否启用")

class SourceResponse(SourceBase):
    """来源响应模型"""
    id: str = Field(..., description="来源ID")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")

    class Config:
        from_attributes = True


